var userId = window.localStorage.getItem("backstage-access-userId");
var adminName = window.localStorage.getItem("backstage-access-adminName"); // 登录账号
$(function() {

  $("#adminName").val(adminName);

  //提交
  $("body").on("click", "#save-btn", function(event) {
    event.preventDefault();
    var success = $('.form').validate('submitValidate');
    var newPassward = $("#newPassward").val();
    var newComfirmPassward = $("#newComfirmPassward").val();
    if (success && (newPassward == newComfirmPassward)) {
      //验证通过提交表单
      submitFom();
    } else {
      ly.toast("请检查确认密码是否输入有误！")
    }
  })

});

/*
 * 提交表单
 */
function submitFom() {
  var passward = $("#newComfirmPassward").val();

  var obj = {};
  var url = site.apiUrl + "/admin/addAdmin";
	obj = {
		'id': userId,
    'passward': passward
  };
  request({
    url: url,
    data: obj,
    type: "post",
    ajaxform: "true",
    callback: function(f) {
      if (f.code == 200) {
        ly.alert('修改成功', function() {
          window.location.reload();
        });
      } else {
        ly.toast(f.msg);
      }
    }
  });
}